package com.twelve.controller.faker;

import com.github.javafaker.Faker;
import com.twelve.bean.faker.OutWarehouse;
import com.twelve.utils.JqgridUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * @program: twelve
 * @description: 出库统计
 * @author: geyuqi
 * @create: 2018-11-24 10:35
 **/

@Controller
@RequestMapping("/outWarehouse")
public class OutWarehouseController {

    private Faker faker = new Faker(Locale.CHINA);

    @Resource
    private JqgridUtil jqgridUtil;

    /**
     * 跳转页面
     * @param request
     * @return
     */
    @RequestMapping("")
    public String recently(HttpServletRequest request){
        return "faker/outWarehouse";
    }


    /**
     * 出库列表
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public String list(HttpServletRequest request){
        String pageNo = request.getParameter("page"); // 取得当前页数,注意这是jqgrid自身的参数
        String pageSize = request.getParameter("rows"); // 取得每页显示行数，,注意这是jqgrid自身的参数

        List<OutWarehouse> list = new ArrayList<OutWarehouse>();
        for (int i = 0; i < 12; i++) {
            OutWarehouse outWarehouse = new OutWarehouse();
            outWarehouse.setCargoName("乙炔");
            outWarehouse.setUnit("千克");
            outWarehouse.setSpec("$28");
            outWarehouse.setReqNum(faker.number().randomDigit());
            outWarehouse.setRealNum(faker.number().randomDigit());
            outWarehouse.setReqMan(faker.name().name());
            outWarehouse.setRemark("备注");
            list.add(outWarehouse);
        }

        return jqgridUtil.getJson(list, pageNo, 11 , 10);
    }
}
